package com.gjy.concurrency.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-12-13 14:29:31
 */
public class SemaphoreTest {
    private static final Logger logger = LoggerFactory.getLogger(SemaphoreTest.class);
    private static final Semaphore SEMAPHORE = new Semaphore(2);

    public static void main(String[] args) throws InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(2);

        pool.execute(() -> {
            logger.info("aaa");
            SEMAPHORE.release();
        });
        pool.execute(() -> {
            logger.info("aaa");
            SEMAPHORE.release();
        });
        SEMAPHORE.acquire(3);

        pool.shutdown();
    }
}
